<?php
/**
 * Db.php
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@mygem.org so we can send you a copy immediately.
 *
 * @copyright   Copyright (c) 2012, MyGem <info@mygem.org>
 * @package     MyGem
 */


class MyGem_Db
{

    protected static $connection = null;
    protected static $errors = array();

    public static function factory($adapter, $host, $username, $password, $dbname, $params = array())
    {
        $filename = dirname(__FILE__) . DIRECTORY_SEPARATOR
                  . 'db' . DIRECTORY_SEPARATOR
                  . strtolower($adapter) . '.php';
        if (!file_exists($filename))
        {
            $error = "DB Adapter {$adapter} does not exists";
            self::$errors[] = $error;
            trigger_error($error);
            return null;
        }
        require_once $filename;
        $classname = 'MyGem_Db_'.$adapter;
        self::$connection = new $classname($host, $username, $password, $dbname, $params);
        return self::$connection;
    }

    public static function getConnection()
    {
        return self::$connection;
    }

}

